<%@ page isELIgnored="false" %> <!-- isELIgnored=true禁用表达式 -->
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
    <head>
        <meta charset="UTF-8">
        <title>在线商城注册页面</title>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/public.css"/>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/login.css"/>
        <script src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js" type="text/javascript" charset="utf-8"></script>
        <script src="${pageContext.request.contextPath}/js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="${pageContext.request.contextPath}/js/login.js" type="text/javascript" charset="utf-8"></script>

    </head>
    <body>
        <div class="head">
            <div class="shouye_head">
                <a href="${pageContext.request.contextPath}/page/shopping/first.jsp">商城首页</a>
            </div>
        </div>
        <div class="dowebok" id="dowebok">
            <!-- 注册 -->
            <div class="form-container sign-up">
                <form id="form1" >
                    <h1>注册</h1>
                    <input type="text"  id="username" name="uName"  placeholder="请输入用户名" />
<%--                    <input type="text"  id="user_id" name="user_id" placeholder="账号" />--%>
                    <input type="password" id="pwd" name="uPass" placeholder="请输入密码" />
<%--                    <input type="password" id="second_pwd" name="second_pwd" placeholder="请再次输入密码" />--%>
<%--                    <input id="email" id="email" name="email" type="email" placeholder="请输入正确的邮箱格式">--%>
<%--                    <input type="text" id="birth" name="birth" placeholder="出生日期 以YYYY-MM-DD格式" />--%>
                    <input type="text" id="phone" name="uPhone" placeholder="手机号码" />
<%--                    <input type="text" id="address" name="address" placeholder="收货地址" />--%>
                    <button type="button" onclick="register()">注册</button>
                </form>
            </div>
            <!-- 登录 -->
            <div class="form-container sign-in">
                <form class="sign">
                    <h1>登录</h1>
                    <input type="text" name="uName" id="uName" placeholder="账号" value="123">
                    <input type="password" name="uPass" id="uPass" placeholder="密码" value="123">
                    <a href="###">忘记密码？</a>
                    <button type="button" onclick="login()">登录</button>
                </form>
            </div>
            <!-- 两边的蒙版 -->
            <div class="overlay-container">
                <div class="overlay">
                    <!-- 登录蒙版 -->
                    <div class="overlay-panel mask-left">
                        <h1>已有帐号？</h1>
                        <p>请使用您的帐号进行登录</p>
                        <button class="ghost" id="signIn">登录</button>
                    </div>
                    <!-- 注册蒙版 -->
                    <div class="overlay-panel mask-right">
                        <h1>没有帐号？</h1>
                        <p>立即注册加入我们，和我们一起开始旅程吧</p>
                        <button class="ghost" id="signUp">注册</button>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script>
        <%--$(function(){--%>
        <%--    //用户名异步认证--%>
        <%--    $("#uName").change(function(){--%>
        <%--        $.get("${pageContext.request.contextPath}/user/checkUser"+"?uName="+this.value,function(data){--%>
        <%--            if(data==="1"){--%>
        <%--                $("#uNameMsg").html("用户名已经存在").css("color","red");--%>
        <%--                $("#updateUser").attr("disabled",true);--%>
        <%--            }else{--%>
        <%--                $("#uNameMsg").html("用户名可用").css("color","green");--%>
        <%--                $("#updateUser").removeAttr("disabled");--%>
        <%--            }--%>
        <%--        })--%>
        <%--    });--%>
        <%--    //验证手机号--%>
        <%--    $("#uPhone").change(function(){--%>
        <%--        let arr1=/^[1][3|4|5|7|8|9][0-9]{9}$/;--%>
        <%--        var num = this.value;--%>
        <%--        if (arr1.test(num)) {--%>
        <%--            $.get("${pageContext.request.contextPath}/user/checkUser"+"?uPhone="+this.value,function(data){--%>
        <%--                if(data==="1"){--%>
        <%--                    $("#phoneMsg").html("该手机号已注册其他账号").css("color","red");--%>
        <%--                    $("#updateUser").attr("disabled", true);--%>
        <%--                }else{--%>
        <%--                    $("#phoneMsg").html("手机号可用").css("color", "green");--%>
        <%--                    $("#updateUser").removeAttr("disabled");--%>
        <%--                }--%>
        <%--            })--%>
        <%--        } else {--%>
        <%--            $("#phoneMsg").html("请输入正确的手机号！").css("color", "red");--%>
        <%--            $("#updateUser").attr("disabled", true);--%>
        <%--        }--%>
        <%--    });--%>
        <%--    //密码--%>
        <%--    // $("#uPass").change(function(){--%>
        <%--    //     $("#updateUser").removeAttr("disabled");--%>
        <%--    // });--%>
        <%--});--%>

        function register(){
            $("#form1").submit(function(e){
                e.preventDefault();
                return false;
            });
            // window.location.href = "index.jsp";
        }

        function login(){
            //登录参数验证
            var uName = $("#uName").val();
            if(uName == ''){
                alert("请输入用户名");
                return;
            }
            var uPass = $("#uPass").val();
            if(uPass == ''){
                alert("请输入密码");
                return;
            }
            var params = "uName="+uName+"&uPass="+uPass;
            //提交登录信息
            $.ajax({
                url: "http://localhost:8080/shopping/user/userLogin",
                data: params,
                type: "post",
                success:function(str){
                    console.info(str);
                    if(str != '0'){
                        alert("登录成功");
                        //跳主页
                        window.location.href="http://localhost:8080/shopping/user/loginUser?id="+str;
                    } else {
                        alert("登陆失败")
                        window.location.reload();
                    }
                }
            });
        }
        function register(){
            //登录参数验证
            var uName = $("#username").val();
            if(uName == ''){
                alert("请输入用户名");
                return;
            }

            var uPass = $("#pwd").val();
            if(uPass == ''){
                alert("请输入密码");
                return;
            }

            var uPhone = $("#phone").val();
            if(uPhone == ''){
                alert("请输入手机号");
                return;
            }
            var params = "uName="+uName+"&uPass="+uPass+"&uPhone="+uPhone;
            //提交登录信息
            $.ajax({
                url: "http://localhost:8080/shopping/user/register",
                data: params,
                type: "post",
                success:function(str){
                    console.info(str);
                    if(str == '1'){
                        alert("注册成功");
                        window.location.reload();
                    } else if (str == '2'){
                        alert("用户名已被注册")
                        window.location.reload();
                    }else if (str == '3'){
                        alert("手机号已注册账号")
                        window.location.reload();
                    }else if (str == '0'){
                        alert("注册失败")
                        window.location.reload();
                    }
                }
            });
        }
    </script>
</html>
